<!---

Copyright 2008:

Author: Marco van den Oever
Company: WSO
Website: http://www.webserviceonline.biz
Email: marco@webserviceonline.biz

License: 

This software is licensed under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
For a copy of the GNU General Public License check the license folder or see <http://www.gnu.org/licenses/>.

Description:

wsoFarcryBanners, a Farcry plugin to show and rotate banners from one or more banner clients on a Farcry based project

Build with great support from the Farcry-Dev group! (Google on Farcry-Dev)

Created: 14/09/08

Tested on CF8

--->
<cfsetting enablecfoutputonly="true" />
<!--- set banner id list --->
<cfparam name="APPLICATION[stObj.ObjectID]" type="string" default="">
<!--- when no id's are available anymore --->
<cfset obj = createObject('component',application.stcoapi.banners.packagepath) />
<cfif listLen(APPLICATION[stObj.ObjectID]) EQ 0>
  <!--- get the banner id's --->
  <cfset props = {} />
  <cfset props.whereclause="(abannerclients) IN (SELECT data FROM #application.dbowner#rulebanners_abannerclients WHERE #application.dbowner#rulebanners_abannerclients.parentid = '#stObj.ObjectID#') AND showstatus = 'onhits' AND hitsleft > 0" />
  <cfset onhits = obj.getMultipleByQuery(argumentCollection=props) />
  <cfif onhits.recordcount GT 0>
    <cfset banids = valueList(onhits.objectid)>
    <cfelse>
    <cfset banids = "">
  </cfif>
  <cfset props = {} />
  <cfset props.whereclause="(abannerclients) IN (SELECT data FROM #application.dbowner#rulebanners_abannerclients WHERE #application.dbowner#rulebanners_abannerclients.parentid = '#stObj.ObjectID#') AND showstatus = 'onviews' AND viewsleft > 0" />
  <cfset onviews = obj.getMultipleByQuery(argumentCollection=props) />
  <cfif onviews.recordcount GT 0>
    <cfset banids = ListAppend(banids, valueList(onviews.ObjectID))>
  </cfif>
  <cfset props = {} />
  <cfset props.whereclause="(abannerclients) IN (SELECT data FROM #application.dbowner#rulebanners_abannerclients WHERE #application.dbowner#rulebanners_abannerclients.parentid = '#stObj.ObjectID#') AND showstatus = 'always'" />
  <cfset always = obj.getMultipleByQuery(argumentCollection=props) />
  <cfif always.recordcount GT 0>
    <cfset banids = ListAppend(banids, valueList(always.ObjectID))>
    <cfelse>
    <cfset banids = banids>
  </cfif>
  <!--- set the banner id's to unique application var --->
  <cfset APPLICATION[stObj.ObjectID] = banids>
</cfif>
<!--- get the first banner id when available, else set bannerID to "" --->
<cfif listLen(APPLICATION[stObj.ObjectID]) gt 0>
  <cfset bannerID = listGetAt(APPLICATION[stObj.ObjectID], 1)>
  <cfelse>
  <cfset bannerID = "">
</cfif>
<cfif APPLICATION[stObj.ObjectID] GT 0>
  <!--- set the current banner views + 1 --->
  <cfset viewsmade = obj.getData(bannerID) />
  <cfset props = {} />
  <cfset props.objectid = bannerID />
  <cfset props.viewsmade = viewsmade.viewsmade + 1 />
  <cfset props.user="anonymous" />
  <cfset obj.setData(stProperties=props) />
</cfif>
<!--- if there is a banner id list, reset the list minus the current banner id so the next page load will show the next banner --->
<cfif listLen(APPLICATION[stObj.ObjectID]) gt 0>
  <cfset APPLICATION[stObj.ObjectID] = listDeleteAt(APPLICATION[stObj.ObjectID], 1)>
</cfif>
<!--- get the current banner info based on the current banner id --->
<cfif isdefined('viewsmade.objectid')>
  <cfset bannerinfo = obj.getData(bannerID) />
</cfif>
<!--- if based on the current banner id there is banner info to display show, else show nothing --->

<cfif isdefined('bannerinfo.objectid')>
  <!--- set the current banner views - 1 if greater then 0 --->
  <cfif #bannerinfo.viewsleft# NEQ "0">
    <!--- set the current banner views - 1 --->
    <cfset viewsleft = obj.getData(bannerID) />
    <cfset props = {} />
    <cfset props.objectid = bannerID />
    <cfset props.viewsleft = viewsleft.viewsleft - 1 />
    <cfset props.user="anonymous" />
    <cfset obj.setData(stProperties=props) />
  </cfif>
  <cfoutput><a href="#application.url.webRoot#?objectid=#url.objectid#&amp;id=#bannerID#" target="_blank"><img src="#application.url.imageRoot##bannerinfo.bannerimg#" border="0" alt="#bannerinfo.bannername#" title="#bannerinfo.bannername#" /></a>
    <cfif IsdeFined("URL.id") and #URL.id# neq "">
      <!--- get the current banner url based on the current URL.id --->
      <cfset bannerurl = obj.getData(URL.id) />
      <!--- set the current banner hits + 1 --->
      <cfset hitsmade = obj.getData(url.id) />
      <cfset props = {} />
      <cfset props.objectid = url.id />
      <cfset props.hitsmade = hitsmade.hitsmade + 1 />
      <cfset props.user="anonymous" />
      <cfset obj.setData(stProperties=props) />
      <!--- set the current banner hits - 1 if greater then 0 --->
      <cfif #bannerinfo.hitsleft# NEQ "0">
        <cfset hitsleft = obj.getData(url.id) />
        <cfset props = {} />
        <cfset props.objectid = url.id />
        <cfset props.hitsleft=hitsleft.hitsleft - 1 />
        <cfset props.user="anonymous" />
        <cfset obj.setData(stProperties=props) />
      </cfif>
      <cflocation url="#bannerurl.bannerurl#" addtoken="No">
    </cfif>
  </cfoutput>
</cfif>
<cfsetting enablecfoutputonly="false" />
